import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
import { config } from './config';
import { ValidationPipe } from '@nestjs/common';
import { WsAdapter } from '@nestjs/platform-ws';
import * as csurf from 'csurf';
async function bootstrap() {
  const app = await NestFactory.create(AppModule, { cors: true });
  // 添加api前缀
  app.setGlobalPrefix('api');
  // 使用管道
  app.useGlobalPipes(new ValidationPipe());
  // websocket
  app.useWebSocketAdapter(new WsAdapter(app));
  //防止csrf攻击
  // app.use(csurf());
  // 快速生成接口文档Swagger
  const swaggerCoCnfig = new DocumentBuilder()
    .setTitle('CarMail example')
    .setDescription('The CarMail API description')
    .setVersion('1.0')
    .addTag('CarMail')
    .build();
  const document = SwaggerModule.createDocument(app, swaggerCoCnfig);
  SwaggerModule.setup('api', app, document);
  // 监听端口
  await app.listen(config.port);
}
bootstrap();
